//
//  RBGoodsConfirmVC.m
//  zhongzhenglu
//
//  Created by XL on 2022/9/8.
//

#import "RBGoodsConfirmVC.h"
#import "RBDefine.h"
#import "UIView+RBAdd.h"
#import "UIScrollView+RBAdd.h"
#import <Masonry.h>
#import "RBThemeConfig.h"
#import <UIColor+YYAdd.h>
#import <UIView+YYAdd.h>
#import "RBPager.h"
#import "RanTool.h"
#import "UIViewController+RBAdd.h"
#import "RBGoodsConfirmPointsPopVC.h"
#import "RBGoodsConfirmBillPopVC.h"
#import "RBGoodsConfirmChooseCouponPopVC.h"

@interface RBGoodsConfirmVC ()

@property(nonatomic, strong)UIScrollView *scrollView;

@property(nonatomic, strong)IBOutlet UIView *addressView;
@property(nonatomic, strong)IBOutlet UILabel *addressNameL;
@property(nonatomic, strong)IBOutlet UILabel *addressL;

@property(nonatomic, strong)IBOutlet UIView *shopView;
@property(nonatomic, strong)IBOutlet UIImageView *shopImgView;
@property(nonatomic, strong)IBOutlet UILabel *shopNameL;
@property(nonatomic, strong)IBOutlet UIImageView *goodsImgView;
@property(nonatomic, strong)IBOutlet UILabel *goodsNameL;
@property(nonatomic, strong)IBOutlet UILabel *goodsAttL;
@property(nonatomic, strong)IBOutlet UILabel *goodsNumL;
@property(nonatomic, strong)IBOutlet UILabel *goodsPriceL;

@property(nonatomic, strong)IBOutlet UIView *noteView;
@property(nonatomic, strong)IBOutlet UITextView *noteTextView;

@property(nonatomic, strong)IBOutlet UIView *bottomView;
@property(nonatomic, strong)IBOutlet UILabel *totalPriceL;


@end

@implementation RBGoodsConfirmVC

#pragma mark - Lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setup];
    [self fillData];
}

#pragma mark - Private

- (void)setup
{
    self.title = @"确认购买";
    [self.bottomView zoomSubViewsWithSelf];
    [self.view addSubview:self.bottomView];
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(Zoom(self.bottomView.height));
        make.bottom.mas_equalTo(-kRBSafeBottomHeight);
    }];
    [self.shopView zoomSubViewsWithSelf];
    self.shopView.height = Zoom(self.shopView.height);
    [self.noteView zoomSubViewsWithSelf];
    self.noteView.height = Zoom(self.noteView.height);
}

- (void)fillData
{
    self.addressNameL.numberOfLines = 0;
    self.addressNameL.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
        [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(15)] color:[RBThemeConfig textBlackColor] string:@"收货人：美少女" lineSpacing:Zoom(4)];
        [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(15)] color:[RBThemeConfig textBlackColor] string:@"　" lineSpacing:Zoom(4)];
        [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(13)] color:[UIColor colorWithHexString:@"#969593"] string:@"15045651100" lineSpacing:Zoom(4)];
    }];
    self.addressL.numberOfLines = 0;
    self.addressL.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
        [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(14)] color:[UIColor colorWithHexString:@"#4D4948"] string:@"黑龙江省 哈尔滨市 道里区 爱建街道爱建路13号 黑龙江龙采科技集团" lineSpacing:Zoom(4)];
    }];
    self.totalPriceL.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
        [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(16)] color:[UIColor colorWithHexString:@"#F23030"] string:@"￥"];
        [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(22)] color:[UIColor colorWithHexString:@"#F23030"] string:@"2608.00"];
    }];
    [self.scrollView rbSetContentWidth:kRBMainScreenWidth];
    [self.scrollView addView:self.addressView withHeight:CGFLOAT_MIN width:Zoom(350) top:Zoom(10) bottom:0 left:CGFLOAT_MIN right:CGFLOAT_MIN centerX:YES];
    [self.scrollView addView:self.shopView withHeight:self.shopView.height width:Zoom(350) top:Zoom(10) bottom:0 left:CGFLOAT_MIN right:CGFLOAT_MIN centerX:YES];
    [self.scrollView addView:({
        UIView *view = UIView.new;
        view.backgroundColor = UIColor.whiteColor;
        [view rbSetCornerRadius:Zoom(8)];
        [view view_addView:({
            UILabel *view = UILabel.new;
            view.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
                [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(15)] color:[RBThemeConfig textBlackColor] string:@"产品规格信息"];
                [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(12)] color:[RBThemeConfig textGrayColor] string:@"　选填，可在下单加工时详细填写"];
            }];
            view;
        }) withHeight:Zoom(52) width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(16) right:0 centerX:0];
        [view view_addView:[self itemViewWithTitle:@"属性" des:@"传统印模" desGray:NO hideArrow:NO] withHeight:Zoom(36) width:CGFLOAT_MIN top:0 bottom:Zoom(7) left:Zoom(15) right:Zoom(12) centerX:0];
        [view view_addView:[self itemViewWithTitle:@"牙位选择" des:@"" desGray:NO hideArrow:NO] withHeight:Zoom(36) width:CGFLOAT_MIN top:0 bottom:Zoom(7) left:Zoom(15) right:Zoom(12) centerX:0];
        [view view_addView:[self itemViewWithTitle:@"16色比色板" des:@"" desGray:NO hideArrow:NO] withHeight:Zoom(36) width:CGFLOAT_MIN top:0 bottom:Zoom(7) left:Zoom(15) right:Zoom(12) centerX:0];
        [view view_addView:[self itemViewWithTitle:@"26色比色板" des:@"" desGray:NO hideArrow:NO] withHeight:Zoom(36) width:CGFLOAT_MIN top:0 bottom:Zoom(7) left:Zoom(15) right:Zoom(12) centerX:0];
        [view view_addView:[self itemViewWithTitle:@"产品规格" des:@"单冠/连冠" desGray:NO hideArrow:NO] withHeight:Zoom(36) width:CGFLOAT_MIN top:0 bottom:Zoom(7) left:Zoom(15) right:Zoom(12) centerX:0];
        [view view_addView:[self itemViewWithTitle:@"选择排牙" des:@"" desGray:NO hideArrow:NO] withHeight:Zoom(36) width:CGFLOAT_MIN top:0 bottom:Zoom(7) left:Zoom(15) right:Zoom(12) centerX:0];
        view;
    }) withHeight:CGFLOAT_MIN width:Zoom(350) top:Zoom(10) bottom:0 left:0 right:0 centerX:YES];
    [self.scrollView addView:({
        UIView *view = UIView.new;
        view.backgroundColor = UIColor.whiteColor;
        [view rbSetCornerRadius:Zoom(10)];
        
        [view view_addView:UIView.new withHeight:Zoom(10) width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:0];
        
        [view view_addView:({
            UIView *view = [self itemViewWithTitle:@"优惠券" des:@"暂无" desGray:YES hideArrow:NO];
            [view rbAddTapGesWithTarget:self action:@selector(couponViewTapped)];
            view;
        }) withHeight:Zoom(36) width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(15) right:Zoom(12) centerX:0];
        [view view_addView:({
            UIView *view = [self itemViewWithTitle:@"积分抵扣" des:@"50积分，满100可用" desGray:YES hideArrow:NO];
            [view rbAddTapGesWithTarget:self action:@selector(pointsViewTapped)];
            view;
        }) withHeight:Zoom(36) width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(15) right:Zoom(12) centerX:0];
        
        [view view_addView:UIView.new withHeight:Zoom(10) width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:0];
        
        view;
    }) withHeight:CGFLOAT_MIN width:Zoom(350) top:Zoom(10) bottom:0 left:CGFLOAT_MIN right:CGFLOAT_MIN centerX:YES];
    [self.scrollView addView:({
        UIView *view = UIView.new;
        view.backgroundColor = UIColor.whiteColor;
        [view rbSetCornerRadius:Zoom(8)];
        
        [view view_addView:UIView.new withHeight:Zoom(10) width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:0];
        
        [view view_addView:({
            UIView *view = [self itemViewWithTitle:@"发票" des:@"无需发票" desGray:NO hideArrow:NO];
            [view rbAddTapGesWithTarget:self action:@selector(billViewTapped)];
            view;
        }) withHeight:Zoom(36) width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(15) right:Zoom(12) centerX:0];
        
        [view view_addView:self.noteView withHeight:self.noteView.height width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:0];
        
        [view view_addView:({
            UIView *view = UIView.new;
            view.backgroundColor = [RBThemeConfig lineGrayColor];
            view;
        }) withHeight:1 width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(17) right:Zoom(17) centerX:0];
        
        [view view_addView:[self itemViewWithTitle:@"商品金额" des:@"¥320" desGray:NO hideArrow:YES] withHeight:Zoom(36) width:CGFLOAT_MIN top:Zoom(10) bottom:0 left:Zoom(15) right:Zoom(12) centerX:0];
        
        [view view_addView:[self itemViewWithTitle:@"优惠券" des:@"-¥20" desGray:NO hideArrow:YES] withHeight:Zoom(36) width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(15) right:Zoom(12) centerX:0];
        
        [view view_addView:({
            UIView *view = [self itemViewWithTitle:@"积分抵扣" des:@"¥300" desGray:NO hideArrow:YES];
            view;
        }) withHeight:Zoom(36) width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(15) right:Zoom(12) centerX:0];
        
        [view view_addView:UIView.new withHeight:Zoom(10) width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:0];
        
        view;
    }) withHeight:CGFLOAT_MIN width:Zoom(350) top:Zoom(10) bottom:Zoom(10) left:0 right:0 centerX:1];
}

#pragma mark - Network

#pragma mark - Event

- (void)billViewTapped
{
    RBGoodsConfirmBillPopVC *vc = RBGoodsConfirmBillPopVC.new;
    [self presentVc:vc];
}

- (void)pointsViewTapped
{
    RBGoodsConfirmPointsPopVC *vc = RBGoodsConfirmPointsPopVC.new;
    [self presentVc:vc];
}

- (void)couponViewTapped
{
    RBGoodsConfirmChooseCouponPopVC *vc = RBGoodsConfirmChooseCouponPopVC.new;
    [self presentVc:vc];
}

- (IBAction)confirmBtnTapped:(id)sender
{
    
}

#pragma mark - Setter

#pragma mark - Getter

- (UIScrollView *)scrollView
{
    if (!_scrollView)
    {
        self.scrollView = ({
            UIScrollView *view = UIScrollView.new;
            view.backgroundColor = [RBThemeConfig bgGrayColor];
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(1);
                make.left.right.mas_equalTo(0);
                make.bottom.mas_equalTo(self.bottomView.mas_top);
            }];
            view;
        });
    }
    return _scrollView;
}

- (UIView *)itemViewWithTitle: (NSString *)title des: (NSString *)des desGray:(BOOL)desGray hideArrow: (BOOL)hideArrow
{
    UIView *view = UIView.new;
    
    UIImageView *imgView = UIImageView.new;
    if (hideArrow)
    {
        imgView.hidden = YES;
    }
    imgView.image = [UIImage imageNamed:@"mine_arrow_right"];
    [view addSubview:imgView];
    [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.centerY.mas_equalTo(0);
        make.width.mas_equalTo(Zoom(7));
        make.height.mas_equalTo(Zoom(12));
    }];
    
    UILabel *titleL = [RanTool labelWithFontSize:Zoom(13) weight:0 color:[RBThemeConfig textBlackColor] align:0 text:title];
    [view addSubview:titleL];
    [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.centerY.mas_equalTo(0);
    }];
    
    UILabel *desL = [RanTool labelWithFontSize:Zoom(13) weight:0 color:[RBThemeConfig textBlackColor] align:2 text:des];
    if(desGray)
    {
        desL.textColor = [RBThemeConfig textGrayColor];
    }
    [view addSubview:desL];
    [desL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(imgView.mas_left).offset(-Zoom(12));
    }];
    
    return view;
}

@end
